using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;

/// <summary>
/// Summary description for InfoDao
/// </summary>
public class InfoDao
{
    public InfoDao() { }

    public Info GetInfo(string xmlPath)
    {
        XmlDocument doc = new XmlDocument();
        doc.Load(xmlPath);
        XmlElement root = doc.DocumentElement;

        XmlNode ele = root.SelectSingleNode("Logo");
        string logo = ele.InnerText;

        ele = root.SelectSingleNode("Banner");
        string banner = ele.InnerText;

        ele = root.SelectSingleNode("Company");
        string companyName = ele.InnerText;

        ele = root.SelectSingleNode("Email");
        string admEmail = ele.InnerText;

        ele = root.SelectSingleNode("Address");
        string address = ele.InnerText;

        ele = root.SelectSingleNode("Phone");
        string phone = ele.InnerText;

        ele = root.SelectSingleNode("AboutUs");
        string about = ele.InnerText;

        Info info = new Info(logo, banner, companyName, admEmail, address, phone, about);
        return info;
    }

    public void SaveXml(Info dto, string xmlPath)
    {
        XmlTextWriter wri = new XmlTextWriter(xmlPath, Encoding.Unicode);
        wri.Formatting = Formatting.Indented;
        wri.Indentation = 4;
        wri.WriteStartDocument(true);

        wri.WriteStartElement("SiteInfo"); // <SiteInfo>

        wri.WriteStartElement("Logo");
        wri.WriteString(dto.LogoUrl);
        wri.WriteEndElement();

        wri.WriteStartElement("Banner");
        wri.WriteString(dto.BannerUrl);
        wri.WriteEndElement();

        wri.WriteStartElement("Company");
        wri.WriteString(dto.CompanyName);
        wri.WriteEndElement();

        wri.WriteStartElement("Email");
        wri.WriteString(dto.AdmEmail);
        wri.WriteEndElement();

        wri.WriteStartElement("Address");
        wri.WriteString(dto.Address);
        wri.WriteEndElement();

        wri.WriteStartElement("Phone");
        wri.WriteString(dto.Phone);
        wri.WriteEndElement();

        wri.WriteStartElement("AboutUs");
        wri.WriteString(dto.About);
        wri.WriteEndElement();

        wri.WriteEndElement(); // </SiteInfo>

        wri.WriteEndDocument();
        wri.Flush();
        wri.Close();
    }
}
